<template>
	<div class="saleBox">
		<p>添加销售</p>
		<p>商品名称:
			<select v-model="productId">
				<option value="0">请选择</option>
				<option v-for="item in ProductList" :value='item.id'>{{item.productName}}</option>
			</select>
		</p>
		<p>销售单价:<input type="text" v-model="price"></p>
		<p>销售数量:<input type="text" v-model="quantity"></p>
		<button @click="addSale()">保存</button>
	</div>
</template>

<script>
	import axios from 'axios'
	export default{
		data(){
			return{
				ProductList:[],
				price:"",
				quantity:"",
				productId:"0"
			}
		},
		beforeCreate() {
			var that=this;
			var url="http://localhost:8080/getAllProduct";
			axios.get(url,{
				params:{
					
				}
			}).then(res=>{
					that.ProductList=res.data.data;			
			})
		},
		methods:{
			addSale:function(){
				if(this.productId=='0'){
					alert('请选择商品');
					return;
				}
				var that=this;
				var url="http://localhost:8080/addSale";
				axios.get(url,{
					params:{
						price:that.price,
						quantity:that.quantity,
						productId:that.productId,
						userId:sessionStorage.getItem("id")
					}
				}).then(res=>{
						if(res.data.message=="OK"){
							alert("添加成功！");
						}		
				})
			}
		}
	}
</script>

<style>
	.saleBox{
		text-align: center;
	}
</style>
